/**
 * 版权所有:版权所有(C) 2020，卓信科技
 * 系统名称:FOL
 * 文件名称:FolRequestForReimburseMobileServiceImpl.java
 * 模块名称:TODO(费用报销接口)
 * 创建日期:2020年5月19日
 * 作        者:Baisong
 * 内容摘要:TODO(费用报销接口)
 */
package com.zx.emanage.postLoanManage.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.zx.emanage.FOLApplication;
import com.zx.emanage.postLoanManage.persist.FolFinaBillBusinessTripDetailDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillReimLoanRelationDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillReimburseDetailDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillSubsidiaryDao;
import com.zx.emanage.postLoanManage.persist.FolFinaCollectionPayConfirmDao;
import com.zx.emanage.postLoanManage.service.IFolApplyBillRelationService;
import com.zx.emanage.postLoanManage.service.IFolFinaBillService;
import com.zx.emanage.postLoanManage.service.SendWechatEmailMsgService;
import com.zx.emanage.postLoanManage.vo.FolRequestForMobileSearchBeanVO;
import com.zx.emanage.sysmanage.persist.FolFileInfoDao;
import com.zx.emanage.user.persist.PmPersonnelDao;
import com.zx.emanage.user.vo.PmPersonnel;
import com.zx.emanage.util.gen.CodeNoUtil;
import com.zx.emanage.util.gen.FOLMsgInfo;
import com.zx.emanage.util.gen.ResultHelper;
import com.zx.emanage.util.gen.entity.FolApplyBillRelation;
import com.zx.emanage.util.gen.entity.FolCreApprovalInfo;
import com.zx.emanage.util.gen.entity.FolFileInfo;
import com.zx.emanage.util.gen.entity.FolFinaBill;
import com.zx.emanage.util.gen.entity.FolFinaBillBusinessTripDetail;
import com.zx.emanage.util.gen.entity.FolFinaBillReimLoanRelation;
import com.zx.emanage.util.gen.entity.FolFinaBillReimburseDetail;
import com.zx.emanage.util.gen.entity.FolFinaBillSubsidiary;

/**
 * 类 名 称: FolRequestForReimburseMobileServiceImpl
 * 内容摘要: TODO
 * 作者: wuguoqiang
 *
 * @Date 2020/10/10 13:29
 **/
@Service("folRequestForReimburseMobileService")
public class FolRequestForReimburseMobileServiceImpl
{

    /**
     * 方法名称: initReimburseInfo
     * 内容摘要: TODO(费用报销单初始化)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 13:32
     **/
    public Map<String, Object> initReimburseInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try
        {

            FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
            PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
            FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
            FolFinaCollectionPayConfirmDao folFinaCollectionPayConfirmDao = (FolFinaCollectionPayConfirmDao) FOLApplication
                    .getBean("folFinaCollectionPayConfirmDao");
            FolFinaBillReimLoanRelationDao folfinabillreimloanrelationdao = (FolFinaBillReimLoanRelationDao) FOLApplication
                    .getBean("folFinaBillReimLoanRelationDao");
            Map<String, Object> paramMap = queryInfo.getParamMap();
            Map<String, Object> ret_data = new HashMap<String, Object>();
            Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
            paramMap.put("fol_fina_bill_subsidiary_id_reim", paramMap.get("fol_fina_bill_subsidiary_id"));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            List<Map<String, Object>> reimburseList = new ArrayList<>();
            List<Map<String, Object>> loanRelationList = new ArrayList<>();

			List<Map<String, Object>> collection_information_list = new ArrayList<>();
			PmPersonnel pmPersonnel = pmPersonnelDao.findPersonnelById(paramMap.get("user_id").toString());
			// 是否存在签名
			ret_data.put("is_sign", pmPersonnel.getIs_sign());
            //判断
            if (null != paramMap.get("Initial_sort_id"))
            {
                //1：首次制作
                if (paramMap.get("Initial_sort_id").toString().equals("1"))
                {
					Map<String, Object> cardMap = new HashMap<>();
					cardMap.put("receivables_name", pmPersonnel.getPersonnel_name());
					cardMap.put("receivables_bank", pmPersonnel.getPersonnel_bank_title());
					cardMap.put("receivables_bank_branch", pmPersonnel.getPersonnel_bankName());
					cardMap.put("receivables_bank_number",
							FolRequestForMobileServiceImpl.addSpaceForCardNo(pmPersonnel.getPersonnel_bankCardCode()));

					cardMap.put("receivables_bank_pro", pmPersonnel.getBank_province_code());
					cardMap.put("receivables_bank_city", pmPersonnel.getBank_city_code());
					cardMap.put("receivables_bank_pro_name", pmPersonnel.getBank_province_str());
					cardMap.put("receivables_bank_city_name", pmPersonnel.getBank_city_str());
					cardMap.put("bank_num", pmPersonnel.getBank_num());

					collection_information_list.add(cardMap);
					ret_data.put("card_default", 1);

					// PmPersonnel personnel = pmPersonnelDao.findPersonnelById(user_id.toString());
                    //填报日期
                    ret_data.put("apply_date", sdf.format(new java.sql.Date(System.currentTimeMillis())));
                    //经办人 （姓名 短工号）
                    ret_data.put("apply_user_name",
							pmPersonnel.getPersonnel_name() + " " + pmPersonnel.getPersonnel_shortCode());
                    //职务
					ret_data.put("apply_user_postname", pmPersonnel.getPersonnel_postName());
                    //所属部门
					ret_data.put("apply_user_deptname", pmPersonnel.getPersonnel_deptName());
                    //上级部门
					ret_data.put("apply_user_pdeptname", pmPersonnel.getDept_pname());
                  /*  //收款人
                    ret_data.put("receivables_name", personnel.getPersonnel_name());
                    //开户行
                    ret_data.put("receivables_bank", personnel.getPersonnel_bank_title());
                    //支行
                    ret_data.put("receivables_bank_branch", personnel.getPersonnel_bankName());
                    //卡号
                    ret_data.put("receivables_bank_number", FolRequestForMobileServiceImpl.addSpaceForCardNo(personnel.getPersonnel_bankCardCode()));*/
                }
                else
                {
                    //2：草稿编辑
                    if (paramMap.get("Initial_sort_id").toString().equals("2"))
                    {
                        reimburseList = folFinaBillDao.getConfirmReimburseInfo(paramMap);

                    }
                    //4：单据查看/审批  5：收付款初始化  6：已完成单据查看
                    else
                    {
                        //如果传了审批主键
                        if (paramMap.get("fol_apply_bill_relation_id") != null)
                        {
                            reimburseList = folFinaBillDao.getReimburseInfo(paramMap);
                        }
                        else
                        {
                            reimburseList = folFinaBillDao.getConfirmReimburseInfo(paramMap);
                        }

                    }

                    // 判断
                    if (reimburseList != null && reimburseList.size() > 0)
                    {
                        Map<String, Object> reimburse_map = reimburseList.get(0);
                        //填报日期
                        ret_data.put("apply_date", reimburse_map.get("apply_date"));
                        //经办人 （姓名 短工号）
                        ret_data.put("apply_user_name", reimburse_map.get("apply_user_name_shortcode"));
                        //职务
                        ret_data.put("apply_user_postname", reimburse_map.get("apply_user_postname"));
                        //所属部门
                        ret_data.put("apply_user_deptname", reimburse_map.get("apply_user_deptname"));
                        //上级部门
                        ret_data.put("apply_user_pdeptname", reimburse_map.get("apply_user_pdeptname"));
						// 收款卡默认与否
						ret_data.put("card_default", reimburse_map.get("card_default"));
                        /*//收款人
                        ret_data.put("receivables_name", reimburse_map.get("receivables_name"));
                        //开户行
                        ret_data.put("receivables_bank", reimburse_map.get("receivables_bank"));
                        //支行
                        ret_data.put("receivables_bank_branch", reimburse_map.get("receivables_bank_branch"));
                        //卡号
                        ret_data.put("receivables_bank_number",FolRequestForMobileServiceImpl.addSpaceForCardNo(reimburse_map.get("receivables_bank_number").toString()));*/
                        
                        
                        Map<String, Object> cardMapOther = new HashMap<>();
						// 收款人
						cardMapOther.put("receivables_name", reimburse_map.get("receivables_name"));
						// 开户行
						cardMapOther.put("receivables_bank", reimburse_map.get("receivables_bank"));
						// 支行
						cardMapOther.put("receivables_bank_branch", reimburse_map.get("receivables_bank_branch"));
						// 卡号
						cardMapOther.put("receivables_bank_number", FolRequestForMobileServiceImpl.addSpaceForCardNo(reimburse_map.get("receivables_bank_number").toString()));

						cardMapOther.put("receivables_bank_pro", reimburse_map.get("receivables_bank_pro"));
						cardMapOther.put("receivables_bank_city", reimburse_map.get("receivables_bank_city"));
						cardMapOther.put("receivables_bank_pro_name", reimburse_map.get("receivables_bank_pro_str"));
						cardMapOther.put("receivables_bank_city_name", reimburse_map.get("receivables_bank_city_str"));
						cardMapOther.put("bank_num", reimburse_map.get("bank_num"));

						collection_information_list.add(cardMapOther);
                        //合计金额
                        ret_data.put("total_amount", reimburse_map.get("total_amount"));
                        //报销方式
                        ret_data.put("reimburse_type", reimburse_map.get("reimburse_type"));
                        ret_data.put("reimburse_type_name", reimburse_map.get("reimburse_type_str"));
                        //冲账方式
                        ret_data.put("charge_off_type", reimburse_map.get("charge_off_type"));
                        ret_data.put("charge_off_type_name", reimburse_map.get("charge_off_type_str"));
                        //冲账差额
                        ret_data.put("charge_off_diff_amount", reimburse_map.get("charge_off_diff_amount"));
                        //如果是累加冲账，则赋值冲账差额是0
                        if ((paramMap.get("Initial_sort_id").toString().equals("4") ||
                             paramMap.get("Initial_sort_id").toString().equals("5") ||
                             paramMap.get("Initial_sort_id").toString().equals("6")) &&
                            null != ret_data.get("charge_off_type") &&
                            ret_data.get("charge_off_type").toString().equals("4"))
                        {
                            ret_data.put("charge_off_diff_amount", "0");
                        }
                        //关联借款单
                        ret_data.put("fol_fina_bill_subsidiary_id_relation",
                                     reimburse_map.get("fol_fina_bill_subsidiary_id_relation"));
                        //关联借款单编号
                        ret_data.put("apply_bill_code", reimburse_map.get("apply_bill_code"));
                        //关联借款单金额
                        ret_data.put("apply_total_amount", reimburse_map.get("total_amount_reimburse"));
                        //关联借款单可用余额
                        ret_data.put("apply_balance_amount", reimburse_map.get("apply_balance_amount"));
                        //关联借款单事由
                        ret_data.put("apply_bill_cause", reimburse_map.get("bill_cause_reimburse"));
                        //费用详情
                        List<Map<String, Object>> reimburseDetailList = folFinaBillDao.getReimburseDetailInfo(paramMap);
                        // 判断不为空
                        if (reimburseDetailList != null && reimburseDetailList.size() > 0)
                        {
                            ret_data.put("reimburse_detailList", reimburseDetailList);
                        }
                    }

                    //5：收付款初始化
                    if (paramMap.get("Initial_sort_id").toString().equals("5"))
                    {
                        //默认收付款日期
                        //ret_data.put("confirm_date", sdf.format(new java.sql.Date(System.currentTimeMillis())));

                        //报销方式 1报销2冲账
                        if (ret_data.get("reimburse_type").toString().equals("2"))
                        {
                            //收付款默认带出金额  1 补充打款  2 还借款 3 全额冲账 4 累加冲账
                            if (ret_data.get("charge_off_type").toString().equals("1") ||
                                ret_data.get("charge_off_type").toString().equals("2"))
                            {
                                //取冲账差额
                                ret_data.put("confirm_amount", ret_data.get("charge_off_diff_amount"));
                            }
                            else
                            {
                                //取合计金额
                                ret_data.put("confirm_amount", ret_data.get("total_amount"));
                            }
                        }
                        else if (ret_data.get("reimburse_type").toString().equals("1"))
                        {
                            //取合计金额
                            ret_data.put("confirm_amount", ret_data.get("total_amount"));
                        }
                    }

                    //6：已完成单据查看
                    if (paramMap.get("Initial_sort_id").toString().equals("6"))
                    {
                        List<Map<String, Object>> list = folFinaCollectionPayConfirmDao
                                .getCollectionPayConfirm(paramMap);
                        //判断
                        if (list != null && list.size() > 0)
                        {
                            ret_data.put("confirm_date", list.get(0).get("confirm_date"));
                            ret_data.put("confirm_amount", list.get(0).get("confirm_amount"));

                            Map<String, Object> infoMap = new HashMap<>();
                            infoMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
                            infoMap.put("attachment_module", FOLMsgInfo.FILE_CODE_CWQR);
                            List<Map<String, Object>> pictureList = folFileInfoDao
                                    .getCollectionPayConfirmFiles(infoMap);
                            //判断
                            if (pictureList != null && pictureList.size() > 0)
                            {
                                ret_data.put("pictureList", pictureList);
                            }
                        }
                    }

                    loanRelationList = folfinabillreimloanrelationdao.getRelationLoanBillListMOA(paramMap);
                    // 判断
                    if (loanRelationList != null && loanRelationList.size() > 0)
                    {
                        ret_data.put("loanRelationList", loanRelationList);
                    }
                    else
                    {
                        ret_data.put("loanRelationList", new ArrayList<>());
                    }

                }
                //判断不为空
				if (paramMap.get("fol_fina_bill_id") != null)
                {
                	paramMap.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
					paramMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
					List<Map<String, Object>> img_List = folFileInfoDao.searchMobileInfo(paramMap);
                    // 判断
					if (img_List != null)
                    {
						ret_data.put("img_List", img_List);
                    }
                    else
                    {
						ret_data.put("img_List", new ArrayList<Map<String, Object>>());
                    }	
                }
				else 
                {
					ret_data.put("img_List", new ArrayList<Map<String, Object>>());
                }
                
            }
			// ret_data.put("card_default"//如果选了其他收款卡则需要再给个默认收款卡
			if ("2".equals(ret_data.get("card_default").toString())) 
    		{
				Map<String, Object> cardMap = new HashMap<>();
				cardMap.put("receivables_name", pmPersonnel.getPersonnel_name());
				cardMap.put("receivables_bank", pmPersonnel.getPersonnel_bank_title());
				cardMap.put("receivables_bank_branch", pmPersonnel.getPersonnel_bankName());
				cardMap.put("receivables_bank_number",
						FolRequestForMobileServiceImpl.addSpaceForCardNo(pmPersonnel.getPersonnel_bankCardCode()));

				cardMap.put("receivables_bank_pro", pmPersonnel.getBank_province_code());
				cardMap.put("receivables_bank_city", pmPersonnel.getBank_city_code());
				cardMap.put("receivables_bank_pro_name", pmPersonnel.getBank_province_str());
				cardMap.put("receivables_bank_city_name", pmPersonnel.getBank_city_str());
				cardMap.put("bank_num", pmPersonnel.getBank_num());

				collection_information_list.add(0, cardMap);
    		}
			ret_data.put("collection_information_list", collection_information_list);

            resMap.put("ret_data", ret_data);
            resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
            resMap.put("ret_code", ResultHelper.RET_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", ResultHelper.RET_ERROR);
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return resMap;
    }

    /**
     * 方法名称: initTripInfo
     * 内容摘要: TODO(差旅报销单初始化)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:25
     **/
    public Map<String, Object> initTripInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try
        {
            FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
            PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
            FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
            FolFinaCollectionPayConfirmDao folFinaCollectionPayConfirmDao = (FolFinaCollectionPayConfirmDao) FOLApplication
                    .getBean("folFinaCollectionPayConfirmDao");
            Map<String, Object> paramMap = queryInfo.getParamMap();
            Map<String, Object> ret_data = new HashMap<String, Object>();
            Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            List<Map<String, Object>> reimburseList = new ArrayList<>();
			// 银行卡信息
			List<Map<String, Object>> collection_information_list = new ArrayList<>();
			PmPersonnel personnel = pmPersonnelDao.findPersonnelById(user_id.toString());
			// 是否存在签名
			ret_data.put("is_sign", personnel.getIs_sign());
            //判断
            if (null != paramMap.get("Initial_sort_id"))
            {

                //1：首次制作
                if (paramMap.get("Initial_sort_id").toString().equals("1"))
                {
                	
                	Map<String, Object> cardMap = new HashMap<>();
    				cardMap.put("receivables_name", personnel.getPersonnel_name());
    				cardMap.put("receivables_bank", personnel.getPersonnel_bank_title());
    				cardMap.put("receivables_bank_branch", personnel.getPersonnel_bankName());
    				cardMap.put("receivables_bank_number", FolRequestForMobileServiceImpl.addSpaceForCardNo(personnel.getPersonnel_bankCardCode()));

    				cardMap.put("receivables_bank_pro", personnel.getBank_province_code());
    				cardMap.put("receivables_bank_city", personnel.getBank_city_code());
    				cardMap.put("receivables_bank_pro_name", personnel.getBank_province_str());
    				cardMap.put("receivables_bank_city_name", personnel.getBank_city_str());
    				cardMap.put("bank_num", personnel.getBank_num());

    				collection_information_list.add(cardMap);
    				ret_data.put("collection_information_list", collection_information_list);
    				ret_data.put("card_default", 1);

                    //填报日期
                    ret_data.put("apply_date", sdf.format(new java.sql.Date(System.currentTimeMillis())));
                    //经办人 （姓名 短工号）
                    ret_data.put("apply_user_name",
                                 personnel.getPersonnel_name() + " " + personnel.getPersonnel_shortCode());
                    //职务
                    ret_data.put("apply_user_postname", personnel.getPersonnel_postName());
                    //所属部门
                    ret_data.put("apply_user_deptname", personnel.getPersonnel_deptName());
                    //上级部门
                    ret_data.put("apply_user_pdeptname", personnel.getDept_pname());
                  /*  //收款人
                    ret_data.put("receivables_name", personnel.getPersonnel_name());
                    //开户行
                    ret_data.put("receivables_bank", personnel.getPersonnel_bank_title());
                    //支行
                    ret_data.put("receivables_bank_branch", personnel.getPersonnel_bankName());
                    //卡号
                    ret_data.put("receivables_bank_number",FolRequestForMobileServiceImpl.addSpaceForCardNo(personnel.getPersonnel_bankCardCode()));
                   	*/
                }
                else
                {
                    //2：草稿编辑
                    if (paramMap.get("Initial_sort_id").toString().equals("2"))
                    {
                        reimburseList = folFinaBillDao.getConfirmTripInfo(paramMap);
                    }
                    //4：单据查看/审批 5：收付款初始化 6：已完成单据查看
                    else
                    {
                        //如果传了审批主键
                        if (paramMap.get("fol_apply_bill_relation_id") != null)
                        {
                            reimburseList = folFinaBillDao.getTripInfo(paramMap);
                        }
                        else
                        {
                            reimburseList = folFinaBillDao.getConfirmTripInfo(paramMap);
                        }
                    }

                    // 判断
                    if (reimburseList != null && reimburseList.size() > 0)
                    {
                        Map<String, Object> reimburse_map = reimburseList.get(0);
                        //填报日期
                        ret_data.put("apply_date", reimburse_map.get("apply_date"));
                        //经办人 （姓名 短工号）
                        ret_data.put("apply_user_name", reimburse_map.get("apply_user_name_shortcode"));
                        //职务
                        ret_data.put("apply_user_postname", reimburse_map.get("apply_user_postname"));
                        //所属部门
                        ret_data.put("apply_user_deptname", reimburse_map.get("apply_user_deptname"));
                        //上级部门
                        ret_data.put("apply_user_pdeptname", reimburse_map.get("apply_user_pdeptname"));
						// 收款卡默认与否
						ret_data.put("card_default", reimburse_map.get("card_default"));
                       /* //收款人
                        ret_data.put("receivables_name", reimburse_map.get("receivables_name"));
                        //开户行
                        ret_data.put("receivables_bank", reimburse_map.get("receivables_bank"));
                        //支行
                        ret_data.put("receivables_bank_branch", reimburse_map.get("receivables_bank_branch"));
                        //卡号
                        ret_data.put("receivables_bank_number", FolRequestForMobileServiceImpl.addSpaceForCardNo(reimburse_map.get("receivables_bank_number").toString()));*/

						Map<String, Object> cardMapOther = new HashMap<>();
						 //收款人
						cardMapOther.put("receivables_name", reimburse_map.get("receivables_name"));
                        //开户行
						cardMapOther.put("receivables_bank", reimburse_map.get("receivables_bank"));
                        //支行
						cardMapOther.put("receivables_bank_branch", reimburse_map.get("receivables_bank_branch"));
                        //卡号
						cardMapOther.put("receivables_bank_number", FolRequestForMobileServiceImpl.addSpaceForCardNo(reimburse_map.get("receivables_bank_number").toString()));

						cardMapOther.put("receivables_bank_pro", reimburse_map.get("receivables_bank_pro"));
						cardMapOther.put("receivables_bank_city", reimburse_map.get("receivables_bank_city"));
						cardMapOther.put("receivables_bank_pro_name", reimburse_map.get("receivables_bank_pro_str"));
						cardMapOther.put("receivables_bank_city_name", reimburse_map.get("receivables_bank_city_str"));
						cardMapOther.put("bank_num", reimburse_map.get("bank_num"));

						collection_information_list.add(cardMapOther);

                        //合计金额
                        ret_data.put("total_amount", reimburse_map.get("total_amount"));
                        //事由
                        ret_data.put("bill_cause", reimburse_map.get("bill_cause"));
                        //同行人
                        //ret_data.put("business_trip_users_name", reimburse_map.get("business_trip_users_str"));
                        //同行人id
                        //ret_data.put("business_trip_users", reimburse_map.get("business_trip_users"));
                        String business_trip_users_list_str = (
                                reimburse_map.get("business_trip_users_list") != null ?
                                reimburse_map.get("business_trip_users_list").toString() : null);

                        //判断
                        if (business_trip_users_list_str != null && !business_trip_users_list_str.equals(""))
                        {
                            List<Map<String, Object>> list = new ArrayList<>();
                            String[] business_trip_users = business_trip_users_list_str.split(",");
                            //循环
                            for (String users_str : business_trip_users)
                            {
                                Map<String, Object> map = new HashMap<>();
                                String[] business_trip_user_info = users_str.split("-");
                                map.put("personnel_id", business_trip_user_info[0]);
                                map.put("personnel_name", business_trip_user_info[1]);
                                map.put("personnel_shortcode", business_trip_user_info[2]);
                                map.put("personnel_sex", business_trip_user_info[3]);
                                list.add(map);
                            }

                            //同行人
                            ret_data.put("business_trip_users_list", list);
                        }

                        //起日
                        ret_data.put("business_trip_startdate", reimburse_map.get("business_trip_startdate"));
                        //止日
                        ret_data.put("business_trip_enddate", reimburse_map.get("business_trip_enddate"));
                        //单据数
                        ret_data.put("business_trip_bill", reimburse_map.get("business_trip_bill"));
                        //天数
                        ret_data.put("business_trip_days_total", reimburse_map.get("business_trip_days_total"));

                        //费用详情
                        List<Map<String, Object>> reimburseDetailList = folFinaBillDao.getTripDetailInfo(paramMap);
                        // 判断不为空
                        if (reimburseDetailList != null && reimburseDetailList.size() > 0)
                        {
                            ret_data.put("trip_detailList", reimburseDetailList);
                        }
                    }

                    //5：收付款初始化
                    if (paramMap.get("Initial_sort_id").toString().equals("5"))
                    {
                        //默认收付款日期
                        //ret_data.put("confirm_date", sdf.format(new java.sql.Date(System.currentTimeMillis())));
                        //默认收付款金额
                        ret_data.put("confirm_amount", ret_data.get("total_amount"));

                    }

                    //6：已完成单据查看
                    if (paramMap.get("Initial_sort_id").toString().equals("6"))
                    {
                        List<Map<String, Object>> list = folFinaCollectionPayConfirmDao
                                .getCollectionPayConfirm(paramMap);
                        //判断
                        if (list != null && list.size() > 0)
                        {
                            ret_data.put("confirm_date", list.get(0).get("confirm_date"));
                            ret_data.put("confirm_amount", list.get(0).get("confirm_amount"));

                            Map<String, Object> infoMap = new HashMap<>();
                            infoMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
                            infoMap.put("attachment_module", FOLMsgInfo.FILE_CODE_CWQR);
                            List<Map<String, Object>> pictureList = folFileInfoDao
                                    .getCollectionPayConfirmFiles(infoMap);
                            //判断
                            if (pictureList != null && pictureList.size() > 0)
                            {
                                ret_data.put("pictureList", pictureList);
                            }
                        }

                    }
                }
                //判断不为空
				if (paramMap.get("fol_fina_bill_id") != null)
                {
                	paramMap.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
					paramMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
					List<Map<String, Object>> img_List = folFileInfoDao.searchMobileInfo(paramMap);
                    // 判断
					if (img_List != null)
                    {
						ret_data.put("img_List", img_List);
                    }
                    else
                    {
						ret_data.put("img_List", new ArrayList<Map<String, Object>>());
                    }	
                }
				else 
                {
					ret_data.put("img_List", new ArrayList<Map<String, Object>>());
                }
            }
			// ret_data.put("card_default"//如果选了其他收款卡则需要再给个默认收款卡
			if ("2".equals(ret_data.get("card_default").toString()))
			{
				Map<String, Object> cardMap = new HashMap<>();
				cardMap.put("receivables_name", personnel.getPersonnel_name());
				cardMap.put("receivables_bank", personnel.getPersonnel_bank_title());
				cardMap.put("receivables_bank_branch", personnel.getPersonnel_bankName());
				cardMap.put("receivables_bank_number",
						FolRequestForMobileServiceImpl.addSpaceForCardNo(personnel.getPersonnel_bankCardCode()));

				cardMap.put("receivables_bank_pro", personnel.getBank_province_code());
				cardMap.put("receivables_bank_city", personnel.getBank_city_code());
				cardMap.put("receivables_bank_pro_name", personnel.getBank_province_str());
				cardMap.put("receivables_bank_city_name", personnel.getBank_city_str());
				cardMap.put("bank_num", personnel.getBank_num());

				collection_information_list.add(0, cardMap);
			}
			ret_data.put("collection_information_list", collection_information_list);
            resMap.put("ret_data", ret_data);
            resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
            resMap.put("ret_code", ResultHelper.RET_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", ResultHelper.RET_ERROR);
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return resMap;
    }

    /**
     * 方法名称: saveReimburseInfo
     * 内容摘要: TODO(费用报销单提交)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:27
     **/
    @Transactional
    public Map<String, Object> saveReimburseInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();

        FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
        PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
        FolFinaBillSubsidiaryDao folFinaBillSubsidiaryDao = (FolFinaBillSubsidiaryDao) FOLApplication
                .getBean("folFinaBillSubsidiaryDao");
        FolFinaBillReimburseDetailDao folFinaBillReimburseDetailDao = (FolFinaBillReimburseDetailDao) FOLApplication
                .getBean("folFinaBillReimburseDetailDao");

        FolFinaBillReimLoanRelationDao folfinabillreimloanrelationdao = (FolFinaBillReimLoanRelationDao) FOLApplication
                .getBean("folFinaBillReimLoanRelationDao");

        IFolApplyBillRelationService folApplyBillRelationService = (IFolApplyBillRelationService) FOLApplication
                .getBean("folapplybillrelationService");

        IFolFinaBillService folFinaBillService = (IFolFinaBillService) FOLApplication.getBean("folfinabillService");
        SendWechatEmailMsgService sendWechatEmailMsgService = (SendWechatEmailMsgService) FOLApplication
                .getBean("sendWechatEmailMsgService");

        FolApplyBillRelationServiceImpl folApplyBillRelationServiceImpl = (FolApplyBillRelationServiceImpl) FOLApplication
                .getBean("folapplybillrelationService");

        FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
        
        Map<String, Object> paramMap = queryInfo.getParamMap();
        Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
        PmPersonnel personnel = pmPersonnelDao.findPersonnelById(user_id.toString());

        Map<String, Object> ret_data = new HashMap<String, Object>();

        //判断借款单是否有可用余额,若没有则提示不能提交
        if (paramMap.get("Initial_sort_id").toString().equals("1") &&
            paramMap.get("loanRelationList") != null)
        {

            List<FolFinaBillReimLoanRelation> relationLoanBillList = new ArrayList<>();
            String reimburse_list = paramMap.get("loanRelationList").toString();
            JSONArray arrayList = JSONArray.parseArray(reimburse_list);
            relationLoanBillList = JSONObject
                    .parseArray(arrayList.toJSONString(), FolFinaBillReimLoanRelation.class);

            String codes = "";
            // 循环
            for (FolFinaBillReimLoanRelation bean : relationLoanBillList)
            {
                Map<String, Object> param = new HashMap<>();
                param.put("fol_fina_bill_subsidiary_id_relation", bean.getFol_fina_bill_subsidiary_id_loan());

                Map<String, Object> ffb = folFinaBillDao.getLoanApplicationBill(param);

                //判断若借款单没有可用余额
                if (new BigDecimal(ffb.get("balance_amount").toString()).compareTo(new BigDecimal("0")) < 1)
                {
                    codes += "," + ffb.get("bill_code").toString();
                }
            }

            //判断
            if (!codes.equals(""))
            {
                codes = codes.substring(1);
                resMap.put("ret_data", "当前单据关联的【借款单" + codes + "】已被占用，或可用余额已发生改变。请重新确认后再提交！");
                resMap.put("ret_msg", ResultHelper.RET_ERROR);
                resMap.put("ret_code", ResultHelper.RET_ERROR);
                return resMap;
            }

        }

        FolFinaBill bean1 = new FolFinaBill();
        FolFinaBillSubsidiary bean2 = new FolFinaBillSubsidiary();
        
        String card_default = paramMap.get("card_default") != null ? paramMap.get("card_default").toString() : "1";
        bean2.setCard_default(Integer.parseInt(card_default));
        // 判断
        if(card_default.equals("2"))
        {
    		bean2.setReceivables_name(paramMap.get("receivables_name") != null ? paramMap.get("receivables_name").toString() : "");
    		bean2.setReceivables_bank(paramMap.get("receivables_bank") != null ? paramMap.get("receivables_bank").toString() : "");
    		bean2.setReceivables_bank_branch(paramMap.get("receivables_bank_branch") != null ? paramMap.get("receivables_bank_branch").toString() : "");
    		bean2.setReceivables_bank_number(paramMap.get("receivables_bank_number") != null ? paramMap.get("receivables_bank_number").toString() : "");
    		bean2.setReceivables_bank_pro(
    			(paramMap.get("receivables_bank_pro") != null && !paramMap.get("receivables_bank_pro").toString().equals("")) ? 
    				paramMap.get("receivables_bank_pro").toString() : null
    		);
    		bean2.setReceivables_bank_city(
    			(paramMap.get("receivables_bank_city") != null && !paramMap.get("receivables_bank_city").toString().equals("")) ?
    				paramMap.get("receivables_bank_city").toString() : null
    		);
    		bean2.setBank_num(paramMap.get("bank_num") != null ? paramMap.get("bank_num").toString() : "");
        }
        else
        {
        	bean2.setReceivables_name(personnel.getPersonnel_name());
    		bean2.setReceivables_bank(personnel.getPersonnel_bank_title());
    		bean2.setReceivables_bank_branch(personnel.getPersonnel_bankName());
        	bean2.setReceivables_bank_number(personnel.getPersonnel_bankCardCode());
        	bean2.setReceivables_bank_pro(personnel.getBank_province_code());
        	bean2.setReceivables_bank_city(personnel.getBank_city_code());
        	bean2.setBank_num(personnel.getBank_num());
        }
        
        //编辑
        if (paramMap.get("fol_fina_bill_id") != null && paramMap.get("fol_fina_bill_subsidiary_id") != null)
        {
            java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());
            
            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean1, paramMap);
            bean1.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            //1：提交 2：暂存
            if (paramMap.get("Initial_sort_id").toString().equals("1"))
            {
                bean1.setBill_state(2);
            }
            else if (paramMap.get("Initial_sort_id").toString().equals("2"))
            {
                bean1.setBill_state(1);
            }
            // bean1.setApply_date(new java.sql.Date(now_timestamp.getTime()));
            folFinaBillDao.update(bean1);

            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean2, paramMap);
            bean2.setFol_fina_bill_subsidiary_id(
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString()));
            bean2.setFol_fina_bill_subsidiary_id_relation(
                    paramMap.get("fol_fina_bill_subsidiary_id_relation") != null ?
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id_relation").toString()) : null);
            bean2.setCharge_off_type(
                    paramMap.get("charge_off_type") != null ?
                    Integer.parseInt(paramMap.get("charge_off_type").toString()) : null);
            bean2.setCharge_off_diff_amount(
                    paramMap.get("charge_off_diff_amount") != null ?
                    new BigDecimal(paramMap.get("charge_off_diff_amount").toString()) : null);
            bean2.setReimburse_type(
                    paramMap.get("reimburse_type") != null ?
                    Integer.parseInt(paramMap.get("reimburse_type").toString()) : null);
            bean2.setFol_fina_bill_id(bean1.getFol_fina_bill_id());

            bean2.setTotal_amount(paramMap.get("total_amount") != null ?
                                  new BigDecimal(paramMap.get("total_amount").toString()) : null);

            List<FolFinaBillReimburseDetail> reimburseDetailList = new ArrayList<>();
            //判断
            if (paramMap.get("reimburse_list") != null)
            {
                // json转list
                String list_str = paramMap.get("reimburse_list").toString();
                JSONArray arrayList = JSONArray.parseArray(list_str);
                reimburseDetailList = JSONObject
                        .parseArray(arrayList.toJSONString(), FolFinaBillReimburseDetail.class);
                // 如果多条费用报销，详情表只保存一条
                if (reimburseDetailList.size() > 1)
                {
                    bean2.setBill_cause(reimburseDetailList.get(0).getReasons_cost() + "等");
                }
                else
                {
                    bean2.setBill_cause(reimburseDetailList.get(0).getReasons_cost());
                }
            }

            folFinaBillSubsidiaryDao.update(bean2);

            FolFinaBillReimburseDetail ffbrd = new FolFinaBillReimburseDetail();
            ffbrd.setEnable_flag(0);
            ffbrd.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            ffbrd.setFol_fina_bill_subsidiary_id(
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString()));
            folFinaBillReimburseDetailDao.delOriginalReimburseDetail(ffbrd);

            //判断
            if (paramMap.get("reimburse_list") != null)
            {
                // 循环插入
                for (FolFinaBillReimburseDetail bean3 : reimburseDetailList)
                {
                    bean3.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
                    bean3.setFol_fina_bill_subsidiary_id(bean2.getFol_fina_bill_subsidiary_id());
                    bean3.setCreate_timestamp(now_timestamp);
                    bean3.setCreate_user_id(personnel.getPersonnel_id());
                    bean3.setCreate_user_name(personnel.getPersonnel_name());
                    bean3.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
                    bean3.setLast_update_timestamp(now_timestamp);
                    bean3.setLast_update_user_id(personnel.getPersonnel_id());
                    bean3.setEnable_flag(1);
                }
                folFinaBillReimburseDetailDao.batchSave(reimburseDetailList);
            }

            FolFinaBillReimLoanRelation ffbrlr = new FolFinaBillReimLoanRelation();
            ffbrlr.setFol_fina_bill_subsidiary_id_reim(bean2.getFol_fina_bill_subsidiary_id());
            ffbrlr.setEnable_flag(0);
            folfinabillreimloanrelationdao.update(ffbrlr);

            List<FolFinaBillReimLoanRelation> relationLoanBillList = new ArrayList<>();
            //判断
            if (paramMap.get("loanRelationList") != null && "2".equals(paramMap.get("reimburse_type").toString()))
            {
                String reimburse_list = paramMap.get("loanRelationList").toString();
                JSONArray arrayList = JSONArray.parseArray(reimburse_list);
                relationLoanBillList = JSONObject
                        .parseArray(arrayList.toJSONString(),
                                    FolFinaBillReimLoanRelation.class);

                // 循环插入
                for (FolFinaBillReimLoanRelation bean4 : relationLoanBillList)
                {
                    bean4.setFol_fina_bill_subsidiary_id_reim(bean2.getFol_fina_bill_subsidiary_id());
                    bean4.setEnable_flag(1);
                }
                folfinabillreimloanrelationdao.batchSave(relationLoanBillList);
            }
            
            // 删除附件
            Map<String, Object> paramMap_file = new HashMap<String, Object>();
            paramMap_file.put("fol_id", bean1.getFol_fina_bill_id());
            paramMap_file.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
			folFileInfoDao.deleteFilesForDJSQ(paramMap_file);

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            if (bean1.getBill_state().intValue() == 2)
            {

                // 报销方式 1报销2冲账
                if (bean2.getReimburse_type() != null && bean2.getReimburse_type() == 2)
                {
                    /*
                     * FolFinaBillSubsidiary folFinaBillSubsidiary = folFinaBillSubsidiaryDao
                     * .get(bean2.getFol_fina_bill_subsidiary_id()); //不为空 if
                     * (folFinaBillSubsidiary.getFol_fina_bill_subsidiary_id_relation() != null) {
                     * // 更新关联借款单的余额字段 Map<String, Object> pMap = new HashMap<>();
                     * pMap.put("fol_fina_bill_subsidiary_id",
                     * folFinaBillSubsidiary.getFol_fina_bill_subsidiary_id_relation());
                     * folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap); }
                     */
                    // 更新关联借款单的余额字段
                    Map<String, Object> pMap = new HashMap<>();

                    pMap.put("fol_fina_bill_subsidiary_id_reim", bean2.getFol_fina_bill_subsidiary_id());

                    List<Map<String, Object>> listMap = folfinabillreimloanrelationdao
                            .getReimLoanRelationInfo(pMap);
                    // 是否为空
                    if (listMap != null && listMap.size() > 0)
                    {
                        // 循环
                        for (Map<String, Object> map : listMap)
                        {
                            pMap.put("fol_fina_bill_subsidiary_id", map.get("fol_fina_bill_subsidiary_id_loan"));
                            folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap);
                        }
                    }
                }

                paramMap = folFinaBillSubsidiaryDao.getBillInfo(paramMap);
                //判断是否存在
                if (!paramMap.containsKey("relation_num")
                    || Integer.valueOf(paramMap.get("relation_num").toString()) <= 0)
                {
                    /**
                     * @param id 申请人
                     * @param bill_id 单据id
                     * @param apply_type 审批类型
                     * @param var 条件参数
                     */
                    List<FolApplyBillRelation> folApplyList = folApplyBillRelationServiceImpl
                            .getFOLFlowRelationByUserId(
                                    paramMap.get("apply_user_id").toString(), bean1.getFol_fina_bill_id(),
                                    Integer.valueOf(paramMap.get("bill_type").toString()),
                                    paramMap.get("total_amount").toString());
                    // 判断不为空
                    if (folApplyList != null && folApplyList.size() > 0)
                    {
                        folApplyBillRelationServiceImpl.saveBatch(folApplyList, personnel);
                    }
                }

                FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
                // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
                approvalBean.setApproval_result("4");
                // 审批意见
                approvalBean.setApproval_advice("提交成功。");
                // 流程节点code
                approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_TJ);
                // 流程节点名称
                approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_TJ);
                approvalBean.setFol_id(bean1.getFol_fina_bill_id());
                // 流程生成
                folFinaBillService.generateApprovalBean(approvalBean, personnel);
                try
                {
                    Map<String, Object> send_msg_param = new HashMap<>();
                    bean1 = folFinaBillDao.get(bean1.getFol_fina_bill_id());
                    send_msg_param.put("msg_code", "10001");
                    send_msg_param.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
                    send_msg_param.put("bill_code", bean1.getBill_code());
                    send_msg_param.put("user_name_shortcode",
                                       personnel.getPersonnel_name() + " " + personnel.getPersonnel_shortCode());
                    send_msg_param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_DSP);
                    sendWechatEmailMsgService.sendWechat(send_msg_param);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        //新增
        else
        {
            java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());
            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean1, paramMap);
            bean1.setBill_code(CodeNoUtil.getReimburseCode());
            bean1.setApply_date(new java.sql.Date(now_timestamp.getTime()));
            bean1.setApply_user_id(personnel.getPersonnel_id());
            bean1.setApply_user_name(personnel.getPersonnel_name());
            bean1.setApply_user_shrotcode(personnel.getPersonnel_shortCode());
            bean1.setApply_user_postname(personnel.getPersonnel_postName());
            bean1.setApply_user_postid(personnel.getPersonnel_postId());
            bean1.setApply_user_deptid(personnel.getPersonnel_deptId());
            bean1.setApply_user_deptname(personnel.getPersonnel_deptName());
            bean1.setApply_user_pdeptid(personnel.getDept_pid());
            bean1.setApply_user_pdeptname(personnel.getDept_pname());
            bean1.setBill_type(2);
            //1：提交 2：暂存
            if (paramMap.get("Initial_sort_id").toString().equals("1"))
            {
                bean1.setBill_state(2);
            }
            else if (paramMap.get("Initial_sort_id").toString().equals("2"))
            {
                bean1.setBill_state(1);
            }
            // 审批当前级别
            bean1.setCurrent_level(1);
            // 是否可以撤销 1可以 0不可以
            bean1.setIs_revoke(1);
            bean1.setCreate_timestamp(now_timestamp);
            bean1.setCreate_user_id(personnel.getPersonnel_id());
            bean1.setCreate_user_name(personnel.getPersonnel_name());
            bean1.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
            bean1.setLast_update_timestamp(now_timestamp);
            bean1.setLast_update_user_id(personnel.getPersonnel_id());
            bean1.setEnable_flag(1);
            folFinaBillDao.save(bean1);

            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean2, paramMap);
            bean2.setFol_fina_bill_subsidiary_id_relation(
                    paramMap.get("fol_fina_bill_subsidiary_id_relation") != null ?
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id_relation").toString()) : null);
            bean2.setCharge_off_type(
                    paramMap.get("charge_off_type") != null ?
                    Integer.parseInt(paramMap.get("charge_off_type").toString()) : null);
            bean2.setCharge_off_diff_amount(
                    paramMap.get("charge_off_diff_amount") != null ?
                    new BigDecimal(paramMap.get("charge_off_diff_amount").toString()) : null);
            bean2.setReimburse_type(
                    paramMap.get("reimburse_type") != null ?
                    Integer.parseInt(paramMap.get("reimburse_type").toString()) : null);
            bean2.setTotal_amount(paramMap.get("total_amount") != null ?
                                  new BigDecimal(paramMap.get("total_amount").toString()) : null);
            bean2.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
            bean2.setEnable_flag(1);

            List<FolFinaBillReimburseDetail> reimburseDetailList = new ArrayList<>();
            //判断
            if (paramMap.get("reimburse_list") != null)
            {
                //费用详情list
                String reimburse_list = paramMap.get("reimburse_list").toString();
                JSONArray arrayList = JSONArray.parseArray(reimburse_list);
                reimburseDetailList = JSONObject
                        .parseArray(arrayList.toJSONString(),
                                    FolFinaBillReimburseDetail.class);
                // 如果多条费用报销，详情表只保存一条
                if (reimburseDetailList.size() > 1)
                {
                    bean2.setBill_cause(reimburseDetailList.get(0).getReasons_cost() + "等");
                }
                else
                {
                    bean2.setBill_cause(reimburseDetailList.get(0).getReasons_cost());
                }

            }

            folFinaBillSubsidiaryDao.save(bean2);

            //判断
            if (paramMap.get("reimburse_list") != null)
            {
                // 循环插入
                for (FolFinaBillReimburseDetail bean3 : reimburseDetailList)
                {
                    bean3.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
                    bean3.setFol_fina_bill_subsidiary_id(bean2.getFol_fina_bill_subsidiary_id());
                    bean3.setCreate_timestamp(now_timestamp);
                    bean3.setCreate_user_id(personnel.getPersonnel_id());
                    bean3.setCreate_user_name(personnel.getPersonnel_name());
                    bean3.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
                    bean3.setLast_update_timestamp(now_timestamp);
                    bean3.setLast_update_user_id(personnel.getPersonnel_id());
                    bean3.setEnable_flag(1);
                }
                folFinaBillReimburseDetailDao.batchSave(reimburseDetailList);
            }

            List<FolFinaBillReimLoanRelation> relationLoanBillList = new ArrayList<>();
            //判断
            if (paramMap.get("loanRelationList") != null && "2".equals(paramMap.get("reimburse_type").toString()))
            {
                String reimburse_list = paramMap.get("loanRelationList").toString();
                JSONArray arrayList = JSONArray.parseArray(reimburse_list);
                relationLoanBillList = JSONObject
                        .parseArray(arrayList.toJSONString(),
                                    FolFinaBillReimLoanRelation.class);

                // 循环插入
                for (FolFinaBillReimLoanRelation bean4 : relationLoanBillList)
                {
                    bean4.setFol_fina_bill_subsidiary_id_reim(bean2.getFol_fina_bill_subsidiary_id());
                    bean4.setEnable_flag(1);
                }
                folfinabillreimloanrelationdao.batchSave(relationLoanBillList);
            }

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            if (bean1.getBill_state().intValue() == 2)
            {
                /**
                 * @param id  申请人
                 * @param bill_id 单据id
                 * @param apply_type 审批类型
                 * @param var 条件参数
                 */
                List<FolApplyBillRelation> folApplyList = folApplyBillRelationService
                        .getFOLFlowRelationByUserId(bean1.getApply_user_id().toString(),
                                                    bean1.getFol_fina_bill_id(),
                                                    bean1.getBill_type(), bean2.getTotal_amount().toString());
                //判断不为空
                if (folApplyList != null && folApplyList.size() > 0)
                {
                    folApplyBillRelationService.saveBatch(folApplyList, personnel);
                }

                // 单据类型 1借款 2费用报销 3出差报销
                // 报销方式 1报销2冲账
                if (bean2.getReimburse_type() != null && bean2.getReimburse_type() == 2
                    && bean2.getFol_fina_bill_subsidiary_id() != null)
                {
                     /*   // 更新关联借款单的余额字段
                        Map<String, Object> pMap = new HashMap<>();
                        pMap.put("fol_fina_bill_subsidiary_id", bean2.getFol_fina_bill_subsidiary_id_relation());
                        folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap);*/

                    // 更新关联借款单的余额字段
                    Map<String, Object> pMap = new HashMap<>();

                    pMap.put("fol_fina_bill_subsidiary_id_reim", bean2.getFol_fina_bill_subsidiary_id());

                    List<Map<String, Object>> listMap = folfinabillreimloanrelationdao
                            .getReimLoanRelationInfo(pMap);
                    // 是否为空
                    if (listMap != null && listMap.size() > 0)
                    {
                        // 循环
                        for (Map<String, Object> map : listMap)
                        {
                            pMap.put("fol_fina_bill_subsidiary_id", map.get("fol_fina_bill_subsidiary_id_loan"));
                            folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap);
                        }
                    }
                }

                FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
                // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
                approvalBean.setApproval_result("4");
                // 审批意见
                approvalBean.setApproval_advice("提交成功。");
                // 流程节点code
                approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_TJ);
                // 流程节点名称
                approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_TJ);
                approvalBean.setFol_id(bean1.getFol_fina_bill_id());
                // 流程生成
                folFinaBillService.generateApprovalBean(approvalBean, personnel);
                try
                {
                    Map<String, Object> send_msg_param = new HashMap<>();
                    send_msg_param.put("msg_code", "10001");
                    send_msg_param.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
                    send_msg_param.put("bill_code", bean1.getBill_code());
                    send_msg_param.put("user_name_shortcode",
                                       personnel.getPersonnel_name() + " " + personnel.getPersonnel_shortCode());
                    send_msg_param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_DSP);
                    sendWechatEmailMsgService.sendWechat(send_msg_param);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }

        // 判断
        if(paramMap.get("img_List") != null)
        {
        	List<FolFileInfo> file_list = JSON
                    .parseObject(paramMap.get("img_List").toString(), new TypeReference<List<FolFileInfo>>()
                    {
                    });
            // 循环
            for (FolFileInfo bean_file : file_list)
            {
				bean_file.setFol_file_info_id(null);
            	bean_file.setAttachment_new_name(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf("\\") + 1));
            	bean_file.setAttachment_type(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf(".")));
                bean_file.setAttachment_module(FOLMsgInfo.FILE_CODE_DJSQ);
                bean_file.setData_type_name(FOLMsgInfo.FILE_CODE_DJSQ_T);
                bean_file.setData_detail_name(FOLMsgInfo.FILE_CODE_DJSQ_D);
                bean_file.setFol_id(bean1.getFol_fina_bill_id());
                bean_file.setFol_other_id(bean2.getFol_fina_bill_subsidiary_id());
                bean_file.setEnable_flag(1);
                folFileInfoDao.save(bean_file);
            }
        }
        
        resMap.put("ret_data", ret_data);
        resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
        resMap.put("ret_code", ResultHelper.RET_SUCCESS);

        return resMap;
    }

    /**
     * 方法名称: saveTripInfo
     * 内容摘要: TODO(差旅报销单提交)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:28
     **/
    @Transactional
    public Map<String, Object> saveTripInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();

        FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
        PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
        FolFinaBillSubsidiaryDao folFinaBillSubsidiaryDao = (FolFinaBillSubsidiaryDao) FOLApplication
                .getBean("folFinaBillSubsidiaryDao");
        FolFinaBillBusinessTripDetailDao folFinaBillBusinessTripDetailDao = (FolFinaBillBusinessTripDetailDao) FOLApplication
                .getBean("folFinaBillBusinessTripDetailDao");

        IFolApplyBillRelationService folApplyBillRelationService = (IFolApplyBillRelationService) FOLApplication
                .getBean("folapplybillrelationService");

        IFolFinaBillService folFinaBillService = (IFolFinaBillService) FOLApplication.getBean("folfinabillService");
        SendWechatEmailMsgService sendWechatEmailMsgService = (SendWechatEmailMsgService) FOLApplication
                .getBean("sendWechatEmailMsgService");
        FolApplyBillRelationServiceImpl folApplyBillRelationServiceImpl = (FolApplyBillRelationServiceImpl) FOLApplication
                .getBean("folapplybillrelationService");
        
        FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d = null;

        Map<String, Object> paramMap = queryInfo.getParamMap();
        Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
        PmPersonnel personnel = pmPersonnelDao.findPersonnelById(user_id.toString());

        Map<String, Object> ret_data = new HashMap<String, Object>();

        FolFinaBill bean1 = new FolFinaBill();
        FolFinaBillSubsidiary bean2 = new FolFinaBillSubsidiary();
        
        String card_default = paramMap.get("card_default") != null ? paramMap.get("card_default").toString() : "1";
        bean2.setCard_default(Integer.parseInt(card_default));
        // 判断
        if(card_default.equals("2"))
        {
    		bean2.setReceivables_name(paramMap.get("receivables_name") != null ? paramMap.get("receivables_name").toString() : "");
    		bean2.setReceivables_bank(paramMap.get("receivables_bank") != null ? paramMap.get("receivables_bank").toString() : "");
    		bean2.setReceivables_bank_branch(paramMap.get("receivables_bank_branch") != null ? paramMap.get("receivables_bank_branch").toString() : "");
    		bean2.setReceivables_bank_number(paramMap.get("receivables_bank_number") != null ? paramMap.get("receivables_bank_number").toString() : "");
    		bean2.setReceivables_bank_pro(
    			(paramMap.get("receivables_bank_pro") != null && !paramMap.get("receivables_bank_pro").toString().equals("")) ? 
    				paramMap.get("receivables_bank_pro").toString() : null
    		);
    		bean2.setReceivables_bank_city(
    			(paramMap.get("receivables_bank_city") != null && !paramMap.get("receivables_bank_city").toString().equals("")) ?
    				paramMap.get("receivables_bank_city").toString() : null
    		);
    		bean2.setBank_num(paramMap.get("bank_num") != null ? paramMap.get("bank_num").toString() : "");
        }
        else
        {
        	bean2.setReceivables_name(personnel.getPersonnel_name());
    		bean2.setReceivables_bank(personnel.getPersonnel_bank_title());
    		bean2.setReceivables_bank_branch(personnel.getPersonnel_bankName());
        	bean2.setReceivables_bank_number(personnel.getPersonnel_bankCardCode());
        	bean2.setReceivables_bank_pro(personnel.getBank_province_code());
        	bean2.setReceivables_bank_city(personnel.getBank_city_code());
        	bean2.setBank_num(personnel.getBank_num());
        }
        
        //编辑
        if (paramMap.get("fol_fina_bill_id") != null && paramMap.get("fol_fina_bill_subsidiary_id") != null)
        {
            java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());
            
            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean1, paramMap);
            bean1.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            //1：提交 2：暂存
            if (paramMap.get("Initial_sort_id").toString().equals("1"))
            {
                bean1.setBill_state(2);
            }
            else if (paramMap.get("Initial_sort_id").toString().equals("2"))
            {
                bean1.setBill_state(1);
            }
            // bean1.setApply_date(new java.sql.Date(now_timestamp.getTime()));
            folFinaBillDao.update(bean1);

            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean2, paramMap);
            bean2.setFol_fina_bill_subsidiary_id(
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString()));

            bean2.setBusiness_trip_bill(paramMap.get("business_trip_bill") != null ?
                                        Integer.parseInt(paramMap.get("business_trip_bill").toString()) : null);

            bean2.setBill_cause(paramMap.get("bill_cause") != null ?
                                paramMap.get("bill_cause").toString() : null);
            //判断
            if (paramMap.get("business_trip_startdate") != null)
            {
                try
                {
                    d = format.parse(paramMap.get("business_trip_startdate").toString());
                    bean2.setBusiness_trip_startdate(new java.sql.Date(d.getTime()));
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }

            //判断
            if (paramMap.get("business_trip_enddate") != null)
            {
                try
                {
                    d = format.parse(paramMap.get("business_trip_enddate").toString());
                    bean2.setBusiness_trip_enddate(new java.sql.Date(d.getTime()));
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }

            bean2.setBusiness_trip_days_total(paramMap.get("business_trip_days_total") != null ?
                                              paramMap.get("business_trip_days_total").toString() :
                                              null);
            bean2.setBusiness_trip_users(paramMap.get("business_trip_users") != null ?
                                         paramMap.get("business_trip_users").toString() : null);
            bean2.setTotal_amount(paramMap.get("total_amount") != null ?
                                  new BigDecimal(paramMap.get("total_amount").toString()) : null);

            folFinaBillSubsidiaryDao.update(bean2);

            FolFinaBillBusinessTripDetail ffbbtd = new FolFinaBillBusinessTripDetail();
            ffbbtd.setEnable_flag(0);
            ffbbtd.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            ffbbtd.setFol_fina_bill_subsidiary_id(
                    Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString()));
            folFinaBillBusinessTripDetailDao.delOriginalBusinessTripDetail(ffbbtd);

            // 删除附件
            Map<String, Object> paramMap_file = new HashMap<String, Object>();
            paramMap_file.put("fol_id", bean1.getFol_fina_bill_id());
            paramMap_file.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
			folFileInfoDao.deleteFilesForDJSQ(paramMap_file);
            
            //判断
            if (paramMap.get("trip_detailList") != null)
            {
                // json转list
                String list_str = paramMap.get("trip_detailList").toString();
                JSONArray arrayList = JSONArray.parseArray(list_str);
                List<FolFinaBillBusinessTripDetail> businessTripDetailList = JSONObject
                        .parseArray(arrayList.toJSONString(),
                                    FolFinaBillBusinessTripDetail.class);
                // 循环插入
                for (FolFinaBillBusinessTripDetail bean3 : businessTripDetailList)
                {
                    bean3.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
                    bean3.setFol_fina_bill_subsidiary_id(bean2.getFol_fina_bill_subsidiary_id());
                    bean3.setCreate_timestamp(now_timestamp);
                    bean3.setCreate_user_id(personnel.getPersonnel_id());
                    bean3.setCreate_user_name(personnel.getPersonnel_name());
                    bean3.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
                    bean3.setLast_update_timestamp(now_timestamp);
                    bean3.setLast_update_user_id(personnel.getPersonnel_id());
                    bean3.setEnable_flag(1);
                }
                folFinaBillBusinessTripDetailDao.batchSave(businessTripDetailList);
            }

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            if (bean1.getBill_state().intValue() == 2)
            {
                paramMap = folFinaBillSubsidiaryDao.getBillInfo(paramMap);
                // 判断是否存在
                if (!paramMap.containsKey("relation_num")
                    || Integer.valueOf(paramMap.get("relation_num").toString()) <= 0)
                {
                    /**
                     * @param id
                     *            申请人
                     * @param bill_id
                     *            单据id
                     * @param apply_type
                     *            审批类型
                     * @param var
                     *            条件参数
                     */
                    List<FolApplyBillRelation> folApplyList = folApplyBillRelationServiceImpl
                            .getFOLFlowRelationByUserId(paramMap.get("apply_user_id").toString(),
                                                        bean1.getFol_fina_bill_id(),
                                                        Integer.valueOf(paramMap.get("bill_type").toString()),
                                                        paramMap.get("total_amount").toString());
                    // 判断不为空
                    if (folApplyList != null && folApplyList.size() > 0)
                    {
                        folApplyBillRelationServiceImpl.saveBatch(folApplyList, personnel);
                    }
                }
                FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
                // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
                approvalBean.setApproval_result("4");
                // 审批意见
                approvalBean.setApproval_advice("提交成功。");
                // 流程节点code
                approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_TJ);
                // 流程节点名称
                approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_TJ);
                approvalBean.setFol_id(bean1.getFol_fina_bill_id());
                // 流程生成
                folFinaBillService.generateApprovalBean(approvalBean, personnel);
                try
                {
                	bean1 = folFinaBillDao.get(bean1.getFol_fina_bill_id());
                    Map<String, Object> send_msg_param = new HashMap<>();
                    send_msg_param.put("msg_code", "10001");
                    send_msg_param.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
                    send_msg_param.put("bill_code", bean1.getBill_code());
                    send_msg_param.put("user_name_shortcode",
                                       personnel.getPersonnel_name() + " " + personnel.getPersonnel_shortCode());
                    send_msg_param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_DSP);
                    sendWechatEmailMsgService.sendWechat(send_msg_param);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        //新增
        else
        {
            java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());
            com.zx.emanage.util.gen.BeanUtils.copyProperties(bean1, paramMap);
            bean1.setBill_code(CodeNoUtil.getReimburseCode());
            bean1.setApply_date(new java.sql.Date(now_timestamp.getTime()));
            bean1.setApply_user_id(personnel.getPersonnel_id());
            bean1.setApply_user_name(personnel.getPersonnel_name());
            bean1.setApply_user_shrotcode(personnel.getPersonnel_shortCode());
            bean1.setApply_user_postname(personnel.getPersonnel_postName());
            bean1.setApply_user_postid(personnel.getPersonnel_postId());
            bean1.setApply_user_deptid(personnel.getPersonnel_deptId());
            bean1.setApply_user_deptname(personnel.getPersonnel_deptName());
            bean1.setApply_user_pdeptid(personnel.getDept_pid());
            bean1.setApply_user_pdeptname(personnel.getDept_pname());
            bean1.setBill_type(3);
            //1：提交 2：暂存
            if (paramMap.get("Initial_sort_id").toString().equals("1"))
            {
                bean1.setBill_state(2);
            }
            else if (paramMap.get("Initial_sort_id").toString().equals("2"))
            {
                bean1.setBill_state(1);
            }

            // 审批当前级别
            bean1.setCurrent_level(1);
            // 是否可以撤销 1可以 0不可以
            bean1.setIs_revoke(1);
            bean1.setCreate_timestamp(now_timestamp);
            bean1.setCreate_user_id(personnel.getPersonnel_id());
            bean1.setCreate_user_name(personnel.getPersonnel_name());
            bean1.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
            bean1.setLast_update_timestamp(now_timestamp);
            bean1.setLast_update_user_id(personnel.getPersonnel_id());
            bean1.setEnable_flag(1);
            folFinaBillDao.save(bean1);

            //com.zx.emanage.util.gen.BeanUtils.copyProperties(bean2, paramMap);
            bean2.setBusiness_trip_bill(paramMap.get("business_trip_bill") != null ?
                                        Integer.parseInt(paramMap.get("business_trip_bill").toString()) : null);

            bean2.setBill_cause(paramMap.get("bill_cause") != null ?
                                paramMap.get("bill_cause").toString() : null);
            //判断
            if (paramMap.get("business_trip_startdate") != null)
            {
                try
                {
                    d = format.parse(paramMap.get("business_trip_startdate").toString());
                    bean2.setBusiness_trip_startdate(new java.sql.Date(d.getTime()));
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }

            //判断
            if (paramMap.get("business_trip_enddate") != null)
            {
                try
                {
                    d = format.parse(paramMap.get("business_trip_enddate").toString());
                    bean2.setBusiness_trip_enddate(new java.sql.Date(d.getTime()));
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

            }

            bean2.setBusiness_trip_days_total(paramMap.get("business_trip_days_total") != null ?
                                              paramMap.get("business_trip_days_total").toString() :
                                              null);
            bean2.setBusiness_trip_users(paramMap.get("business_trip_users") != null ?
                                         paramMap.get("business_trip_users").toString() : null);

            bean2.setTotal_amount(paramMap.get("total_amount") != null ?
                                  new BigDecimal(paramMap.get("total_amount").toString()) : null);
            bean2.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
            bean2.setReceivables_bank(personnel.getPersonnel_bank_title());
            bean2.setReceivables_name(personnel.getPersonnel_name());
            bean2.setReceivables_bank_number(personnel.getPersonnel_bankCardCode());
            bean2.setReceivables_bank_branch(personnel.getPersonnel_bankName());
            bean2.setBank_num(personnel.getBank_num());
            // 报销
            bean2.setReimburse_type(1);
            bean2.setEnable_flag(1);

            folFinaBillSubsidiaryDao.save(bean2);

            //判断
            if (paramMap.get("trip_detailList") != null)
            {
                // json转list
                String list_str = paramMap.get("trip_detailList").toString();
                JSONArray arrayList = JSONArray.parseArray(list_str);
                List<FolFinaBillBusinessTripDetail> businessTripDetailList = JSONObject
                        .parseArray(arrayList.toJSONString(),
                                    FolFinaBillBusinessTripDetail.class);

                // 循环插入
                for (FolFinaBillBusinessTripDetail bean3 : businessTripDetailList)
                {
                    bean3.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
                    bean3.setFol_fina_bill_subsidiary_id(bean2.getFol_fina_bill_subsidiary_id());
                    bean3.setCreate_timestamp(now_timestamp);
                    bean3.setCreate_user_id(personnel.getPersonnel_id());
                    bean3.setCreate_user_name(personnel.getPersonnel_name());
                    bean3.setCreate_user_shortcode(personnel.getPersonnel_shortCode());
                    bean3.setLast_update_timestamp(now_timestamp);
                    bean3.setLast_update_user_id(personnel.getPersonnel_id());
                    bean3.setEnable_flag(1);
                }
                folFinaBillBusinessTripDetailDao.batchSave(businessTripDetailList);
            }

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            if (bean1.getBill_state().intValue() == 2)
            {
                /**
                 * @param id  申请人
                 * @param bill_id 单据id
                 * @param apply_type 审批类型
                 * @param var 条件参数
                 */
                List<FolApplyBillRelation> folApplyList = folApplyBillRelationService
                        .getFOLFlowRelationByUserId(bean1.getApply_user_id().toString(),
                                                    bean1.getFol_fina_bill_id(),
                                                    bean1.getBill_type(), bean2.getTotal_amount().toString());
                //判断不为空
                if (folApplyList != null && folApplyList.size() > 0)
                {
                    folApplyBillRelationService.saveBatch(folApplyList, personnel);
                }

                FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
                // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
                approvalBean.setApproval_result("4");
                // 审批意见
                approvalBean.setApproval_advice("提交成功。");
                // 流程节点code
                approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_TJ);
                // 流程节点名称
                approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_TJ);
                approvalBean.setFol_id(bean1.getFol_fina_bill_id());
                // 流程生成
                folFinaBillService.generateApprovalBean(approvalBean, personnel);
                try
                {
                    Map<String, Object> send_msg_param = new HashMap<>();
                    send_msg_param.put("msg_code", "10001");
                    send_msg_param.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
                    send_msg_param.put("bill_code", bean1.getBill_code());
                    send_msg_param.put("user_name_shortcode",
                                       personnel.getPersonnel_name() + " " + personnel.getPersonnel_shortCode());
                    send_msg_param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_DSP);
                    sendWechatEmailMsgService.sendWechat(send_msg_param);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        
        // 判断
        if(paramMap.get("img_List") != null)
        {
        	List<FolFileInfo> file_list = JSON
                    .parseObject(paramMap.get("img_List").toString(), new TypeReference<List<FolFileInfo>>()
                    {
                    });
            // 循环
            for (FolFileInfo bean_file : file_list)
            {
				bean_file.setFol_file_info_id(null);
            	bean_file.setAttachment_new_name(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf("\\") + 1));
            	bean_file.setAttachment_type(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf(".")));
                bean_file.setAttachment_module(FOLMsgInfo.FILE_CODE_DJSQ);
                bean_file.setData_type_name(FOLMsgInfo.FILE_CODE_DJSQ_T);
                bean_file.setData_detail_name(FOLMsgInfo.FILE_CODE_DJSQ_D);
                bean_file.setFol_id(bean1.getFol_fina_bill_id());
                bean_file.setFol_other_id(bean2.getFol_fina_bill_subsidiary_id());
                bean_file.setEnable_flag(1);
                folFileInfoDao.save(bean_file);
            }
        }

        resMap.put("ret_data", ret_data);
        resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
        resMap.put("ret_code", ResultHelper.RET_SUCCESS);

        return resMap;
    }

    /**
     * 方法名称: getDeptListInfo
     * 内容摘要: TODO(责任部门)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:29
     **/
    public Map<String, Object> getDeptListInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try
        {
            FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
            List<Map<String, Object>> list = folFinaBillDao.getDeptSInfoMOA();

            resMap.put("ret_data", list);
            resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
            resMap.put("ret_code", ResultHelper.RET_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", ResultHelper.RET_ERROR);
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return resMap;
    }

    /**
     * 方法名称: getPersonnelList
     * 内容摘要: TODO(同行人选择)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:29
     **/
    public Map<String, Object> getPersonnelList(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try
        {
            PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
            Map<String, Object> paramMap = queryInfo.getParamMap();

            // 判断
            if (null != paramMap.get("oper_type"))
            {
                paramMap.put("oper_type", paramMap.get("oper_type"));
            }
            // 判断
            if (null != paramMap.get("search_info"))
            {
                paramMap.put("personnel_name", paramMap.get("search_info"));
                paramMap.put("personnel_shortCode", paramMap.get("search_info"));
            }
            List<Map<String, Object>> list = pmPersonnelDao.getPersonnelListForTripMOA(paramMap);

            resMap.put("ret_data", list);
            resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
            resMap.put("ret_code", ResultHelper.RET_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", ResultHelper.RET_ERROR);
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return resMap;
    }

    /**
     * 方法名称: getLoanRelatedList
     * 内容摘要: TODO(关联借款单)
     *
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @Param [queryInfo]
     * @Author: wuguoqiang
     * @time: 2020/10/10 14:30
     **/
    public Map<String, Object> getLoanRelatedList(FolRequestForMobileSearchBeanVO queryInfo)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try
        {
            FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
            Map<String, Object> paramMap = queryInfo.getParamMap();
            List<Map<String, Object>> list = folFinaBillDao.searchLoanBillsListMOA(paramMap);

            resMap.put("ret_data", list);
            resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
            resMap.put("ret_code", ResultHelper.RET_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", ResultHelper.RET_ERROR);
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return resMap;
    }
}
